package cn.ultrarisk.scadmin.manager.scheduler;

import cn.ultrarisk.scadmin.manager.biz.common.service.SchedulerJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

/**
 * BootstrapScheduler
 *
 * @author sevendlong(lin23871@163.com)
 * @date 2014/5/17
 * @since V1.0
 */
@Component
@Lazy(false)
public class BootstrapScheduler {
    @Autowired
    private SchedulerJobService schedulerJobService;

    @PostConstruct
    private void bootstrap() {
        Timer timer = new Timer();
        // 每隔30s执行一次同步
        timer.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                try {
                    schedulerJobService.sync();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, new Date(), 30 * 1000);
    }
}
